create table Location
(
	 [LocationId] int identity(1, 1) primary key
	,[LocationName] nvarchar(256)
	,[LocationTypeId] int
	,[SortDescription] nvarchar(512)
	,[DetailDescription] nvarchar(max)
	,[ContinentId] int
	,[NationalId] int
	,[CityId] int
	,[DistrictId] int
	,[WardId] int
	,[Address] nvarchar(256)
	,[CreatedBy] int
	,[CreatedDate] datetime
	,[UpdatedBy] int
	,[UpdatedDate] datetime
	,[Status] int
)
go

CREATE PROCEDURE LocationGet
	@LocationId int
AS
SELECT *
FROM [Location]
WHERE [Location].[LocationId] = @LocationId	
GO

CREATE PROCEDURE LocationList
AS
SELECT *
FROM [Location]
ORDER BY LocationId DESC
GO

CREATE PROCEDURE LocationInsert
	 @LocationName nvarchar(256)
	,@LocationTypeId int
	,@SortDescription nvarchar(512)
	,@DetailDescription nvarchar(max)
	,@ContinentId int
	,@NationalId int
	,@CityId int
	,@DistrictId int
	,@WardId int
	,@Address nvarchar(256)
	,@CreatedBy int
	,@CreatedDate datetime
	,@UpdatedBy int
	,@UpdatedDate datetime
	,@Status int
AS

INSERT INTO Location (
	 [LocationName]
	,[LocationTypeId]
	,[SortDescription]
	,[DetailDescription]
	,[ContinentId]
	,[NationalId]
	,[CityId]
	,[DistrictId]
	,[WardId]
	,[Address]
	,[CreatedBy]
	,[CreatedDate]
	,[UpdatedBy]
	,[UpdatedDate]
	,[Status]
	
) VALUES (
	 @LocationName
	,@LocationTypeId
	,@SortDescription
	,@DetailDescription
	,@ContinentId
	,@NationalId
	,@CityId
	,@DistrictId
	,@WardId
	,@Address
	,@CreatedBy
	,@CreatedDate
	,@UpdatedBy
	,@UpdatedDate
	,@Status
	
)

select SCOPE_IDENTITY()
GO

CREATE PROCEDURE LocationUpdate
	@LocationId int, 
	@LocationName nvarchar(256), 
	@LocationTypeId int, 
	@SortDescription nvarchar(512), 
	@DetailDescription nvarchar(max), 
	@ContinentId int, 
	@NationalId int, 
	@CityId int, 
	@DistrictId int, 
	@WardId int, 
	@Address nvarchar(256), 
	@CreatedBy int, 
	@CreatedDate datetime, 
	@UpdatedBy int, 
	@UpdatedDate datetime, 
	@Status int 

AS

UPDATE Location SET
	   [LocationName] = @LocationName
	   ,[LocationTypeId] = @LocationTypeId
	   ,[SortDescription] = @SortDescription
	   ,[DetailDescription] = @DetailDescription
	   ,[ContinentId] = @ContinentId
	   ,[NationalId] = @NationalId
	   ,[CityId] = @CityId
	   ,[DistrictId] = @DistrictId
	   ,[WardId] = @WardId
	   ,[Address] = @Address
	   ,[CreatedBy] = @CreatedBy
	   ,[CreatedDate] = @CreatedDate
	   ,[UpdatedBy] = @UpdatedBy
	   ,[UpdatedDate] = @UpdatedDate
	   ,[Status] = @Status
WHERE [Location].[LocationId] = @LocationId
GO

CREATE PROCEDURE LocationDelete
	@LocationId int
AS
DELETE FROM Location
WHERE [Location].[LocationId] = @LocationId
GO